//
//  JddServiceViewController.m
//  PlayBall
//
//  Created by zhazhenwang on 2017/4/1.
//
//

#import "JddServiceViewController.h"
#import "JddServiceKaiJiangCell.h"
#import "JddServiceZiXunCell.h"
#import "JddServiceCaiDianCell.h"
#import "JddViewControllerManager.h"
#import "JddLotteryOpenViewController.h"

@interface JddServiceViewController () <UITableViewDataSource, UITableViewDelegate> {
    UITableView *_mainTableView;
}
@end

@implementation JddServiceViewController

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddServiceViewController);

- (void)viewDidLoad {
    [super viewDidLoad];

//    [self.navigationItem setHidesBackButton:YES];
    self.view.backgroundColor = UIColorFromRGB(0xf7f7f7);
    
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
    customLab.backgroundColor = [UIColor clearColor];
    [customLab setText:PAGE_LOTTERY_SERVICE];
    customLab.textAlignment = NSTextAlignmentCenter;
    
    [customLab setTextColor:[UIColor whiteColor]];
    customLab.font = [UIFont systemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
    self.navigationItem.leftBarButtonItem = nil;
    //self.navigationItem.hidesBackButton = YES;
    
    [self setupUI];
}

- (void)setupUI {
    _mainTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _mainTableView.dataSource = self;
    _mainTableView.delegate = self;
    _mainTableView.showsVerticalScrollIndicator = NO;
    _mainTableView.showsHorizontalScrollIndicator = NO;
    _mainTableView.backgroundColor = [UIColor clearColor];
    _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_mainTableView];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.view setUserInteractionEnabled:YES];
    
    //显示tabbar
    [self setJddTabBarHidden:NO];
    [self setTabBarItemSelect:3];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self setJddTabBarHidden:YES];
}

#pragma mark -- UITableViewDataSource & UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    id cell = nil;
    NSString *cellID = nil;
    NSString *cellClassName = nil;
    switch (indexPath.section) {
        case 0:
            cellID = @"JddServiceKaiJiangCell";
            cellClassName = @"JddServiceKaiJiangCell";
            break;
        case 1:
            cellID = @"JddServiceZiXunCell";
            cellClassName = @"JddServiceZiXunCell";
            break;
        case 2:
            cellID = @"JddServiceCaiDianCell";
            cellClassName = @"JddServiceCaiDianCell";
            break;
    }
    cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:cellClassName owner:nil options:nil] lastObject];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    switch (indexPath.section) {
        case 0: {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOTTERY_OPEN
                                                                    fromController:self
                                                                        withObject:nil
                                                                       withObject2:nil];
        }
            break;
        case 1:
            break;
        case 2:
            break;
    }
}

@end
